<?php
include '../../include/dbFunctions.php';
include ("../../include/function.php");
include ("../../include/image_slider.php");
require ("../../include/class.phpmailer.php");

//Select all school's information
$school_name = "SELECT * FROM school";
$school_name = executeSelectQuery($school_name);


$quer2 = executeSelectQuery("SELECT DISTINCT education_name,education_id FROM education");

if (isset($_GET['cat'])) {
    $cat = $_GET['cat']; //This line is added to take care if your global variable is off
    if (strlen($cat) > 0 and !is_numeric($cat)) {//check if $cat is numeric data or not.
        echo "Data Error";
        exit;
    }
    if (isset($cat) and strlen($cat) > 0) {
        $quer = executeSelectQuery("SELECT DISTINCT school_name, school_id FROM school where education_id=$cat order by school_name");
    } else {
        $quer = executeSelectQuery("SELECT DISTINCT school_name FROM school");
    }
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>Junior Achievement Singapore</title>
        <link href="../../media/css/styles.css" rel="stylesheet" type="text/css" />
        <script type="text/javascript" language="javascript" src="../../media/js/jquery/jquery-1.6.1.min.js"></script>
        <script type="text/javascript" src="../../media/js/jquery/image_slider.js"></script>
        <script src="../../media/js/jquery/custom_jquery.js" type="text/javascript"></script>
        <script type="text/javascript" src="../../media/js/jquery/jquery.form.js"></script>
        <script type="text/javascript" src="../../media/js/jquery/jquery.validate.min.js"></script>
        <!-- Custom jquery scripts -->
        <script src="../..media/js/jquery/custom_jquery.js" type="text/javascript"></script>
        <script src="../..media/js/jquery/jquery.pngFix.pack.js" type="text/javascript"></script>
        <script type="text/javascript" src="../../media/js/jquery/validator_rules.js"></script>
        <script type="text/javascript" charset="utf-8">
            $(document).ready(function() {
                $("#school_form").validate(school_validate);
            } );
            function reload(form){
                var val=form.cat.options[form.cat.options.selectedIndex].value;
                self.location='representativeRegistration.php?cat=' + val ;
            }

        </script>


    </head>
    <body>
        <script>
            var timeout    = 700;
            var closetimer = 0;
            var ddmenuitem = 0;

            function jsddm_open()
            {  jsddm_canceltimer();
                jsddm_close();
                ddmenuitem = $(this).find('ul').css('visibility', 'visible');}

            function jsddm_close()
            {  if(ddmenuitem) ddmenuitem.css('visibility', 'hidden');}

            function jsddm_timer()
            {  closetimer = window.setTimeout(jsddm_close, timeout);}

            function jsddm_canceltimer()
            {  if(closetimer)
                {  window.clearTimeout(closetimer);
                    closetimer = null;}}

            $(document).ready(function()
            {  $('#navigation > li').bind('mouseover', jsddm_open)
                $('#navigation > li').bind('mouseout',  jsddm_timer)});

            document.onclick = jsddm_close;

        </script>
        <div id="container"><!--CONTAINER STARTS-->
            <div id="navigation">
                <li><a href="../../include/home/homepage.php">HOME</a></li>
                <li><a href="../../include/home/contact.php">CONTACT</a></li>
                <li><a href="http://ja.org.sg/">ABOUT JA SINGAPORE</a></li>
                <li><a href="http://jascheduling.lefora.com/">FEEDBACK</a></li>
                <li><a href="../../guide/guide_menu.php">HELP</a></li>

            </div>

            <div id="title"><!--TITLE STARTS-->
            </div><!--TITLE ENDS-->



            <div id="featured"><!--FEATURED AREA STARTS-->

                <div class="featured-image"><!--FEATURED IMAGE STARTS-->
                    <img alt="Featured Image" src="../../media/images/featured_image.png"></img>

                </div><!--FEATURED IMAGE ENDS-->

                <div class="featured-text"><!--FEATURED TEXT STARTS-->

                    <h2>Welcome to JA Singapore</h2>
                    <p>Junior Achievement programs help prepare young people for the real world by showing them how to generate wealth and effectively manage it, how to create jobs which make their communities more robust, and how to apply entrepreneurial thinking to the workplace. <a href="http://www.jaworldwide.org/">Read More... </a></p>

                </div><!--FEATURED TEXT ENDS-->

            </div><!--FEATURED AREA ENDS-->

            <?php
            custom_login();
            ?>


            <div id="left-content"><!--RIGHT CONTENT STARTS-->

                <div class="left-top"><!--RIGHT CONTENT BOX TOP-->
                </div><!--RIGHT CONTENT BOX TOP ENDS-->

                <div class="left-middle"><!--RIGHT CONTENT BOX MIDDLE-->
<h3>School Registration</h3>
                    <form id="school_form" method="post" action="representativeVerifyRegistration.php">
                        <table border="0" cellpadding="0" cellspacing="0"  id="id-form">
                            <!-- Fields for school to input their own information-->
                             <tr>
                                <em>* Required fields</em>
                            </tr><br/><br/>
                            <tr>
                                <th valign="top">School Level <em>*</em> </th>
                                <td>
                                    <select name="cat" class="styledselect_form_1" onchange="reload(this.form)"> 
                                        <option> Select one </option> 
                                    <?php

                                    
                                    for ($i = 0; $i < count($quer2); $i++) {
                                        if ($quer2[$i]['education_id'] == $cat) {
                                            ?>
                                    <option selected="selected" value ="<?php echo$quer2[$i]['education_id'] ?>"> <?php echo$quer2[$i]['education_name'] ?></option>
                                    <?php
                                } else {
                                    ?>
                                   
                                    <option value ="<?php echo$quer2[$i]['education_id'] ?>"> <?php echo$quer2[$i]['education_name'] ?></option>
                                    <?php
                                }
                            }


                            ?>
                                    </select>
                                </td>
                            </tr>
                            <tr>
                                 <th valign="top">School Name <em>*</em> </th>
                                 <td>
                            <select name="subcat" class="styledselect_form_1 required">
                              
                                
                                <?php
                                for ($t = 0; $t < count($quer); $t++) {
                                    ?>
                                    <option value='<?php echo $quer[$t]['school_id'] ?>'><?php echo $quer[$t]['school_name'] ?></option>
                                    <?php
                                }
                                ?>
                            </select>
                            </td>

                            </tr>
                            <tr>
                                <td colspan ="2"><h3>Representative's information: </h3></td>
                            </tr>
                            <tr>
                                <th valign="top">Contact Name <em>*</em> </th>
                                <td><input type="text" name="contact_name" value="" class="inp-form"/></td>
                                <td></td>
                            </tr>
                            <tr>
                                <th valign="top">Contact Salutation <em>*</em></th>
                                <td><select name="contact_salutation" class="styledselect_form_1" value="">
                                        <option value="Mr.">Mr.</option>
                                        <option value="Mrs.">Mrs.</option>
                                        <option value="Ms.">Ms.</option>
                                        <option value="Mdms.">Mdm.</option>
                                        <option value="Dr.">Dr.</option>
                                    </select></td>
                                <td></td>
                            </tr>

                            <tr>
                                <th valign="top">Office number: </th>
                                <td><input type="text" name="office_number" value="" class="inp-form"/></td>
                                <td></td>
                            </tr>
                            <tr>
                                <th valign="top">Mobile number <em>*</em> </th>
                                <td><input type="text" name="mobile_number" value="" class="inp-form"/></td>
                                <td></td>
                            </tr>
                            <tr>
                                <th valign="top">Contact Designation <em>*</em>  </th>
                                <td><input type="text" name="contact_designation" value="" class="inp-form"/></td>
                                <td></td>
                            </tr>
                            <tr>
                                <td colspan ="2"><h3>Account information: </h3></td>
                            </tr>
                            <tr>
                                <th valign="top">Contact Email <em>*</em> </th>
                                <td><input type="text" name="contact_email" value="" class="inp-form"/></td>
                                <td></td>
                            </tr>


                            <tr>
                                <th valign="top">Password <em>*</em> </th>
                                <td><input type="password" name="contact_password" value="" id ="contact_password" class="inp-form"/></td>
                                <td></td>
                            </tr>

                            <tr>
                                <th valign="top"> Retype Password <em>*</em> </th>
                                <td><input type="password" name="retype_password" value="" class="inp-form"/></td>
                                <td></td>
                            </tr>
                        </table>
                        <input type="hidden" name="form_submitted" value="1"/>
                        <input type = "submit" name = "submit" class="form-submit" value=""/>
                    </form>

                </div><!--RIGHT CONTENT BOX MIDDLE ENDS-->

                <div class="left-bottom"><!--RIGHT CONTENT BOX BOTTOM-->
                </div><!--RIGHT CONTENT BOX BOTTOM ENDS-->

            </div><!--RIGHT CONTENT ENDS-->



        </div><!--CONTAINER ENDS-->


        <div id="footer"><!--FOOTER STARTS-->
            <p>Copyright &copy; Junior Achievement Singapore | All Rights Reserved</p>
        </div><!--FOOTER ENDS-->

    </body>
</html>
